package StudyCode.summary.mycollection;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ReturnsACopyOfTheGivenArrayOfTheGivenLength {
	public static void main(String[] argv) {
		byte[] arr = new byte[]{34, 35, 36, 37, 37, 37, 67, 68, 69};
		int newLength = 2;
		System.out.println(java.util.Arrays
				.toString(copyOf(arr, newLength)));
	}


	public static byte[] copyOf(byte[] arr, int newLength) {
		return copyOf(arr, 0, newLength);
	}

	public static byte[] copyOf(byte[] arr, int offset, int newLength) {
		byte[] newArr = new byte[newLength];
		int srcLen = arr.length - offset;
		System.arraycopy(arr, offset, newArr, 0,
				Math.min(srcLen, newLength));
		return newArr;
	}
}
